<!DOCTYPE html>
<html>

<head>
  <title>Message - AIL</title>
	<link rel="icon" href="{{ url_for('static', filename='image/ail-icon.png') }}">

  <!-- Core CSS -->
	<link href="{{ url_for('static', filename='css/bootstrap4.min.css') }}" rel="stylesheet">
	<link href="{{ url_for('static', filename='css/font-awesome.min.css') }}" rel="stylesheet">
	<link href="{{ url_for('static', filename='css/dataTables.bootstrap.min.css') }}" rel="stylesheet">
    <link href="{{ url_for('static', filename='css/tags.css') }}" rel="stylesheet" type="text/css" />
    <link href="{{ url_for('static', filename='css/ail-project.css') }}" rel="stylesheet">

  <!-- JS -->
	<script src="{{ url_for('static', filename='js/jquery.js')}}"></script>
    <script src="{{ url_for('static', filename='js/popper.min.js')}}"></script>
    <script src="{{ url_for('static', filename='js/bootstrap4.min.js') }}"></script>
	<script src="{{ url_for('static', filename='js/jquery.dataTables.min.js')}}"></script>
	<script src="{{ url_for('static', filename='js/dataTables.bootstrap.min.js')}}"></script>
    <script src="{{ url_for('static', filename='js/tags.js') }}"></script>
    <script src="{{ url_for('static', filename='js/helper.js') }}"></script>

	<style>
        .chat-message-left,
        .chat-message-right {
            display: flex;
            flex-shrink: 0;
        }
        .chat-message-right {
            flex-direction: row-reverse;
            margin-left: auto
        }
        .divider:after,
        .divider:before {
            content: "";
            flex: 1;
            height: 2px;
            background: #eee;
        }
	</style>
</head>
<body>

	{% include 'nav_bar.html' %}

	<div class="container-fluid">
		<div class="row">

			{% include 'sidebars/sidebar_objects.html' %}

			<div class="col-12 col-lg-10" id="core_content">

                <div class="card my-3">
                    <div class="card-header" style="background-color:#d9edf7;font-size: 15px">
                        <h3 class="text-secondary">{{ meta["id"] }} :</h3>
                        <ul class="list-group mb-2">
                            <li class="list-group-item py-0">
                                <div class="row">
                                    <div class="col-md-10">
                                        <table class="table">
                                            <thead>
                                                <tr>
                                                    <th></th>
                                                    <th>Date</th>
                                                    <th>Username</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <tr>
                                                    <td>
                                                        <svg height="26" width="26">
                                                            <g class="nodes">
                                                                <circle cx="13" cy="13" r="13" fill="{{ meta["icon"]["color"] }}"></circle>
                                                                <text x="13" y="13" text-anchor="middle" dominant-baseline="central" class="graph_node_icon {{ meta["icon"]["style"] }}" font-size="16px">{{ meta["icon"]["icon"] }}</text>
                                                            </g>
                                                        </svg>
                                                        {{ meta["subtype"] }}
                                                    </td>
                                                    <td>{{ meta['full_date'] }}</td>
                                                    <td>
                                                        {% if 'username' in meta['user-account'] %}
                                                            {{ meta['user-account']['username']['id'] }}
                                                        {% endif %}
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                    <div class="col-md-1">
                                        <div id="sparkline"></div>
                                    </div>
                                </div>
                            </li>
                        </ul>

                        <div>
                            <h5>
                                <span>
                                    {% include 'modals/edit_tag.html' %}

                                    {% for tag in meta['tags'] %}
                                        <button class="btn btn-{{ bootstrap_label[loop.index0 % 5] }}" data-toggle="modal" data-target="#edit_tags_modal"
                                        data-tagid="{{ tag }}" data-objtype="{{ meta['type'] }}" data-objsubtype="" data-objid="{{ meta['id'] }}">
                                            {{ tag }}
                                        </button>
                                    {%  endfor %}
                                    {% include 'modals/add_tags.html' %}
                                    <button type="button" class="btn btn-light" data-toggle="modal" data-target="#add_tags_modal">
                                        <i class="far fa-plus-square"></i>
                                    </button>
                                </span>
                            </h5>
                        </div>

                        <div class="d-flex flex-row-reverse bd-highlight">
                            <div>
                                <a href="{{ url_for('correlation.show_correlation')}}?type={{ meta['type'] }}&id={{ meta['id'] }}" target="_blank">
                                    <button class="btn btn-lg btn-info"><i class="fas fa-project-diagram"></i> Correlations Graph</button>
                                </a>
                            </div>
                            <div>
                                {% with obj_type=meta['type'], obj_id=meta['id'], obj_subtype=''%}
                                    {% include 'modals/investigations_register_obj.html' %}
                                {% endwith %}
                                <div class="mr-2">
                                    <button type="button" class="btn btn-lg btn-primary" data-toggle="modal" data-target="#investigations_register_obj_modal">
                                        <i class="fas fa-microscope"></i> Investigations
                                    </button>
                                </div>
                            </div>
                          </div>

                    </div>
                </div>


                {% if meta['extracted_matches'] %}
                    <div id="accordion_extracted" class="mb-3 mx-3">
                        <div class="card">
                            <div class="card-header py-1" id="heading_extracted">
                                <div class="row">
                                    <div class="col-11">
                                        <div class="mt-2">
                                            <img id="misp-logo" src="{{ url_for('static', filename='image/ail-icon.png')}}" height="32"> Extracted&nbsp;&nbsp;
                                            <div class="badge badge-warning">{{meta['extracted_matches']|length}}</div>
                                        </div>
                                    </div>
                                    <div class="col-1">
                                        <button class="btn btn-link btn-lg py-2 float-right rotate down" data-toggle="collapse" data-target="#collapse_extracted" aria-expanded="true" aria-controls="collapseDecoded">
                                            <i class="fas fa-chevron-circle-down"></i>
                                        </button>
                                    </div>
                                </div>
                            </div>

                            <div id="collapse_extracted" class="collapse" aria-labelledby="heading_extracted" data-parent="#accordion_extracted">
                                <div class="card-body">
                                    <table id="table_extracted" class="table table-striped">
                                        <thead class="thead-dark">
                                        <tr>
                                            <th>Type</th>
                                            <th>ID</th>
                                            <th>Extracted</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        {% for match in meta['extracted_matches'] %}
                                            <tr>
                                                <td>
                                                    <svg height="26" width="26">
                                                        <g class="nodes">
                                                            <circle cx="13" cy="13" r="13" fill="{{ meta['extracted_matches'][match]['icon']['color'] }}"></circle>
                                                            <text x="13" y="13" text-anchor="middle" dominant-baseline="central" class="graph_node_icon {{ meta['extracted_matches'][match]['icon']['style'] }}" font-size="16px">{{ meta['extracted_matches'][match]['icon']['icon'] }}</text>
                                                        </g>
                                                    </svg>
                                                    {{ meta['extracted_matches'][match]['subtype'] }}
                                                </td>
                                                <td>
                                                    {% if meta['extracted_matches'][match]['subtype'] == 'tracker' %}
                                                          <a href="{{ url_for('hunters.show_tracker') }}?uuid={{ meta['extracted_matches'][match]['id'] }}">{{ meta['extracted_matches'][match]['id'] }}</a>
                                                      {% else %}
                                                          {{ meta['extracted_matches'][match]['id'] }}
                                                      {% endif %}
                                                </td>
                                                <td>
                                                    {% for row in meta['extracted_matches'][match]['matches'] %}
                                                        <a href="#{{ row[0] }}:{{row[1] }}">{{ row[2] }}</a><br>
                                                    {% endfor %}
                                                </td>
                                            </tr>
                                        {% endfor %}
                                        </tbody>
                                    </table>
                                </div>
                            </div>

                        </div>
                    </div>
                {% endif %}


                {% include 'objects/image/block_blur_img_slider.html' %}
                {% with translate_url=url_for('chats_explorer.objects_message', id=meta['id']), obj_id=meta['id'] %}
                    {% include 'chats_explorer/block_translation.html' %}
                {% endwith %}

                <div class="text-center my-2">
                    <div class="card-body">
                        <h4 class="card-title">
                            {% if meta['protocol']['icon'] %}
                                <i class="{{ meta['protocol']['icon']['style'] }} {{ meta['protocol']['icon']['icon'] }}"></i>
                            {% endif %}
                            <b>{{ meta['protocol']['id'] }}</b>
                        </h4>
                    </div>
                </div>

                {% if meta['chat'] %}
                    <div class="my-2">
                        {% with meta=meta['chat'],report_mode=False %}
                            {% include 'chats_explorer/basic_card_chat.html' %}
                        {% endwith %}
                    </div>
                {% endif %}


                <div class="position-relative">
                    <div class="chat-messages p-2">

                        <div class="divider d-flex align-items-center mb-4">
                                <p class="text-center h2 mx-3 mb-0" style="color: #a2aab7;">
                                    <span class="badge badge-secondary mb-2" id="date_section_{{ meta['date'] }}">{{ meta['date'] }}</span>
                                </p>
                            </div>

                        {% with message=meta %}
                            {% include 'chats_explorer/block_message.html' %}
                        {% endwith %}

                    </div>
                </div>

            </div>

        </div>
    </div>

<script>
    var chart = {};
    $(document).ready(function(){
        $("#page-Decoded").addClass("active");
        $("#nav_chat").addClass("active");
        $('[data-toggle="popover"]').popover({
            boundary:'window',
        });

  });

function toggle_sidebar(){
	if($('#nav_menu').is(':visible')){
		$('#nav_menu').hide();
		$('#side_menu').removeClass('border-right')
		$('#side_menu').removeClass('col-lg-2')
		$('#core_content').removeClass('col-lg-10')
	}else{
		$('#nav_menu').show();
		$('#side_menu').addClass('border-right')
		$('#side_menu').addClass('col-lg-2')
		$('#core_content').addClass('col-lg-10')
	}
}
</script>

</body>

</html>
